<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
    />
    <meta name="viewport" content="width=device-width" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <title>网格通</title>
	
    <style id="style-1-cropbar-clipper">
      * {
        margin: 0;
        padding: 0;
        text-decoration: none;
      }
      .download {
        width: 100%;
        position: absolute;
        bottom: 100px;
        z-index: 1;
      }
      .download img {
        width: 80%;
        margin-left: 10%;
      }
      .download p {
        font-size: 12px;
        color: #a0a0a0;
        text-align: center;
      }
      #openapp {
        float: right;
        font-size: 12px;
        text-align: center;
        background-color: #4b9ade;
        color: #fff;
        border-color: #4b9ade;
        padding: 10px;
        border-radius: 13px;
        margin: 10px;
      }
    </style>
  </head>

  <body>
    <header>
      <div class="logo"></div>
    </header>
    <p id="openapp" onclick="openApp()">立即打开网格通</p>
    <img
      width="100%"
      height="100%"
      style="position: absolute; top: 0; z-index: -1"
      src="./iosdownload_files/pageBackground.svg"
    />
    <a
      class="download"
      id="download_url"
      href="itms-services://?action=download-manifest&url=https://mcrm.zj.chinamobile.com:5443/down/downnewenv/mcrm.plist"
    >
      <img id="download_icon" src="./iosdownload_files/iOS.svg" />
    </a>
    <div class="download">
      <p id="free">本次下载免流量</p>
      <p id="version">版本:V5.0.8.1 test-01191655</p>
      <p id="environment" style="display: none"></p>
      <p id="update_time" style="display: none">更新时间:####</p>
    </div>

    <div class="main">
      <div id="popbox_bg" style="display: none">
        <div class="popbox">
          微信内无法下载，请点击<span>右上角</span>按钮，选择【<span>在浏览器打开</span>】,即可正常下载
        </div>
      </div>
    </div>
    <script>
      //环境
      let env = "pro";
      let version = document.getElementById("version").innerHTML;
      if (version.indexOf("test") > -1) {
        env = "test";
      } else if (version.indexOf("beta") > -1) {
        env = "pro";
      }
      //操作系统
      const u = navigator.userAgent;
      const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);

	  //微信浏览器
	  var isWeChat = u.match(/MicroMessenger\/([\d\.]+)/);

      changeHref();
      changeDisplay();

      function changeDisplay() {

        let freeEle = document.getElementById("free");
        let envEle = document.getElementById("environment");
        let updateEle = document.getElementById("update_time");

        if (env == "test" || env == "beta") {
          freeEle.style.display = "none";
          envEle.style.display = "block";
          updateEle.style.display = "block";
        }

		if (isWeChat) {
        setTimeout(function () {
          document.getElementById("popbox_bg").style.display = "block";
        }, 200);
      }
      }

      function changeHref() {

        let a = document.getElementById("download_url");
		let icon = document.getElementById("download_icon");
        if (!isiOS) {
          a.href = "./MCRM.apk";
		  icon.href = "./iosdownload_files/Android.svg"
          return;
        }
        if (env == "test") {
          a.href =
            "itms-services://?action=download-manifest&url=https://mcrm.zj.chinamobile.com:5443/down/plist/test.plist";
        } else if (env == "beta") {
          //beta环境
          a.href =
            "itms-services://?action=download-manifest&url=https://mcrm.zj.chinamobile.com:5443/down/downenvbeta/mcrm.plist";
        }
      }

      function openApp() {
        window.location.href = "https://mcrm.zj.chinamobile.com/";

        var isBlur = false;

        setTimeout(function () {
          if (!isBlur) {
            // location.href = "http://www.baidu.com";//下载页
          }
        }, 1000);

        // window 每次失去焦点
        window.onblur = function () {
          console.log("失去焦点");
          isBlur = true;
        };
      }
    </script>
    <script type="text/javascript" src="./iosdownload.js"></script>
  </body>
</html>
